package com.honey.solr.daosupport.method;

import com.honey.compilation.java.JavaVisibility;
import com.honey.compilation.java.Method;
import com.honey.compilation.java.MethodDecoration;
import com.honey.compilation.java.Parameter;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.types.JDKFullyQualifiedJavaType;
import com.honey.generator.java.AbstractClassName;

public class InMethod extends AbstractClassName {
	
	public Method createMethod(){
		Method answer = new Method("in");
		answer.addJavaDocLine("Lucene in查询") ;
		MethodDecoration methodDecoration = answer.getDecoration();
		methodDecoration.setVisibility(JavaVisibility.PRIVATE);
		methodDecoration.setFinal(true);
		answer.setReturnType(new FullyQualifiedJavaType("StringBuilder"));
		Parameter parameter = new Parameter("Enum<?>","name");parameter.addJavaDocLine("查询字段的名称");
		answer.addParameter(parameter);
		parameter = new Parameter(new FullyQualifiedJavaType("java.util.List<?>"),"list");
		answer.addParameter(parameter);parameter.addJavaDocLine("列表");
		parameter = new Parameter(JDKFullyQualifiedJavaType.getBooleanInstance(),"isNot");
		answer.addParameter(parameter);parameter.addJavaDocLine("求反");
		answer.addBodyLine("StringBuilder answer = new StringBuilder();");
		answer.addBodyLine("if(isNot)not(answer)");
		answer.addBodyLine("answer.append(name).append(new char[]{':','('})");
		answer.addBodyLine("boolean space =false ");
		answer.addBodyLine("for(Object obj : list  ){");
		answer.addBodyLine("if( space ) answer.append(' ');else space = true ;");
		answer.addBodyLine("answer.append( obj )");
		answer.addBodyLine("}");
		answer.addBodyLine("answer.append(')')");
		answer.addBodyLine("return (answer)");
		return answer ;
	}
}
